{extend name="common@public/base" /}
{block name="body"}
<link rel="stylesheet" href="/static/css/index/index.css">

<div class="allWrap">
    <div class="listWrap dtWrap">

        <div class="fly-panel" pad20="" style="padding-top: 5px;">
            <div class="layui-form layui-form-pane">
                <div class="layui-tab layui-tab-brief" lay-filter="user">
                    <ul class="layui-tab-title">
                        <li class="layui-this">发表新帖</li>
                    </ul>
                    <div class="layui-form layui-tab-content" id="LAY_ucm" style="padding: 20px 0;">
                        <div class="layui-tab-item layui-show">
                            <form action="{:url('forum/post/add')}" class="ajax-form" method="post">
                                <div class="layui-row layui-col-space15 layui-form-item">
                                    <div class="layui-col-md3"><label class="layui-form-label">所在专栏</label>
                                        <div class="layui-input-block">

                                            <select lay-verify="required" name="type"
                                                    lay-filter="column">
                                                <option></option>
                                                {volist name="typeList" key="tk" id="tl"}
                                                <option value="{$tk}">{$tl}</option>
                                                {/volist}
                                            </select>

                                        </div>
                                    </div>
                                    <div class="layui-col-md9"><label for="L_title"
                                                                      class="layui-form-label">标题</label>
                                        <div class="layui-input-block">
                                            <input type="text" id="L_title" name="title"
                                                   required="" lay-verify="required"
                                                   autocomplete="off"
                                                   class="layui-input"></div>
                                    </div>
                                </div>

                                <div class="layui-form-item layui-form-text">
                                    <div class="layui-input-block">
                                            <textarea id="LAY_content_editor" name="content" required=""
                                                      lay-verify="content"
                                                      placeholder="详细描述" class="layui-textarea fly-editor"
                                                      style="height: 260px;"></textarea></div>
                                </div>


                                <div class="layui-form-item">
                                    <input type="hidden" name="bid" value="{$bid}">
                                    <button class="layui-btn" lay-filter="*" lay-submit="">立即发布</button>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{/block}

{block name="js"}
<script>
    layui.use(['form', 'layedit', 'laydate', 'upload'], function () {
        var form = layui.form
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate;
        var upload = layui.upload;


        var edit_array = [];
        var editor_content = layedit.build('LAY_content_editor');
        edit_array.push(editor_content)
        var form_lock = false;


        //自定义验证规则
        form.verify({
            content: function (value) {
                if (edit_array.length > 0) { //同步编辑器内容到相应textarea
                    for (var i in edit_array) {
                        layedit.sync(edit_array[i]);
                    }
                }
            }
        });


        form.on('submit(main_form)', function (data) {
            if (form_lock) {
                return false;
            }
            form_lock = true;
            $(data.elem).addClass('layui-btn-disabled');
            var method = $(data.form).attr('method');
            var url = $(data.form).attr('action');


            var post_data = data.field;
            delete post_data["file"];
            delete post_data["image"];
            var fun;
            if (method == 'get') {
                fun = $.get;
            } else {
                fun = $.post;
            }

            fun(url, post_data, function (res) {
                ajax_result(res);
                if (!res.url) {
                    form_lock = false;
                    $(data.elem).removeClass('layui-btn-disabled');
                }
            });

            return false;
        });

    });
</script>

{/block}